import Vue from 'vue'
import AppData from '../stores/AppData'

let LoadData = {
    // 开启卡监听
  load () {
    Vue.resetpost('rs/logic/getInitData', {data: {}}, {resolveMsg: null, rejectMsg: null}).then((res) => {
      res.data.singleValues.forEach((item) => {
        AppData.singleValues[item.name] = item.value
      })
      res.data.params.forEach((item) => {
        let value = []
        item.f_paramvalues.forEach((item, index) => {
          value[index] = {}
          value[index].label = item.name
          value[index].value = item.name
        })
        AppData.params[item.name] = value
      })
      res.data.waterbrands.forEach((item, index) => {
        AppData.waterbrands[index] = {}
        AppData.waterbrands[index].label = item.f_meter_brand
        let watermodel = []
        item.watermodel.forEach((item, index) => {
          watermodel[index] = {}
          watermodel[index].label = item.f_meter_style + item.f_type
          watermodel[index].value = item
        })
        item.watermodel = watermodel
        AppData.waterbrands[index].value = item
      })
      AppData.price = res.data.price
      AppData.userprice = res.data.userprice
      AppData.disprice = res.data.disprice
    }).catch((res) => {
      this.msg = res.data
      this.show = true
    })
  }
}

export default LoadData
